package com.hzlj.position.locate.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fz.common.base.converter.QueryWrapperConverterPlus;
import com.fz.common.base.dto.PageParamDTO;
import com.fz.common.base.dto.QueryPageResultDTO;
import com.fz.common.base.dto.SortParamDTO;
import com.hzlj.position.locate.common.dto.reportVideoJzry.ReportVideoJzryQueryParamDTO;
import com.hzlj.position.locate.common.dto.reportVideoJzry.ReportVideoJzryWithJzJbxxDTO;
import com.hzlj.position.locate.common.model.ReportVideoJzry;
import com.hzlj.position.locate.mapper.ReportVideoJzryMapper;
import com.hzlj.sqjz.jz.common.model.JzJbxx;
import com.hzlj.sqjz.jz.mapper.JzJbxxMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 通信联络核查-视频核验(ReportVideoJzry)表操作类
 *
 * @author makejava
 * @date 2023-12-26 11:55:14
 */
@Repository
public class ReportVideoJzryDao extends ServiceImpl<ReportVideoJzryMapper, ReportVideoJzry> {
    @Resource
    private JzJbxxMapper jzJbxxMapper;


    /**
     * 修改数据
     */
    public boolean updateByJzId(boolean call, ReportVideoJzry jzry) {
        LambdaUpdateWrapper<ReportVideoJzry> updateWrapper = new UpdateWrapper<ReportVideoJzry>().lambda()
                .eq(ReportVideoJzry::getId, jzry.getId())
                .eq(!call, ReportVideoJzry::getVideoId, jzry.getVideoId());
        return this.update(jzry, updateWrapper);
    }

    /**
     * 查询列表：不分页
     */
    public List<ReportVideoJzryWithJzJbxxDTO> listReportVideoJzry(ReportVideoJzryQueryParamDTO dto) {
        return reportVideoJzryQuery()
                .list(ReportVideoJzryWithJzJbxxDTO.class, dto, sortParam());
    }

    /**
     * 查询列表：分页
     */
    public QueryPageResultDTO<ReportVideoJzryWithJzJbxxDTO> pageReportVideoJzry(ReportVideoJzryQueryParamDTO dto, PageParamDTO page) {
        page.setSortFns(sortParam().getSortFns());
        return reportVideoJzryQuery()
                .page(ReportVideoJzryWithJzJbxxDTO.class, dto, page);
    }


    private QueryWrapperConverterPlus<JzJbxx> reportVideoJzryQuery() {
        return QueryWrapperConverterPlus.of(jzJbxxMapper)
                .leftJoin(ReportVideoJzry.class, on -> on.eq(ReportVideoJzry::getId, JzJbxx::getId));
    }


    private SortParamDTO sortParam() {
        return SortParamDTO
                .of(false, ReportVideoJzry::getSpotCheckTime);
    }

}

